home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine CD 1995
/
Archive Magazine CD 1995.iso
/
discs
/
shareware
/
share_41
/
assembler
/
examples
/
sum3
< prev
next >
Wrap
Text File
|
1991-05-15
|
2KB
|
58 lines
; NAME sum3
; PURPOSE sums the numbers 0 to number1
; DESIGN
; result <- 0
; load number1
; for number1 <- number1 downto 0
; add number1 to result
; end for
; store result in number3
; NOTE
; this differs from sum2 by unwinding the loop reducing the branching
; this means the pipeline is flushed less ofen
; works for number1 is multiple of 10 only
; sum to 50000 is maximum without overflow
; on arm 2 this takes 0.025 seconds
ldr r7, [r1] ; load number 1 to r7
mov r8, #0 ; set result r8 to zero
.loop
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
add r8, r8, r7 ; add number to result
subs r7, r7, #1 ; decrement the number and set the flags
bgt loop ; branch if its greater than zero back round the loop
str r8, [r3] ; store the result in number 3
; this reduces the branching, decreasing the pipeline flushing
; summing 10 000 000 takes around 5 seconds using arm2
; this is 50% speed improvement but only works for multiples of 10